package bishizhuanyong.百度;


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums=new int[n];
        for (int i=0;i<nums.length;i++)
            nums[i]=sc.nextInt();
        int res=0;
        for (int i=0;i<=nums.length-3;i++){
            while (nums[i]>=1&&nums[i+1]>=2&&nums[i+2]>=3){
                nums[i]-=1;
                nums[i+1]-=2;
                nums[i+2]-=3;
                res+=5;
            }
        }
        for (int i=0;i<nums.length;i++)
            res+=nums[i];
        System.out.println(res);

    }


}
